package com.csgc.camera.widget.dialog

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat
import com.csgc.camera.biz.other.activity.WebViewActivity
import com.csgc.camera.constants.Constants
import com.csgc.camera.util.PrivacyProtocolHelper
import com.csgc.camera.util.ViewUtils
import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.base.AnimAction
import com.csgc.camera.widget.dialog.base.BaseDialog
import com.cysd.spsyxj.R
import com.hjq.shape.layout.ShapeRelativeLayout
import com.hjq.shape.view.ShapeTextView

class BuyVipDialog  constructor(context: Context, @StyleRes themeResId: Int = R.style.BaseDialogTheme):
    BaseDialog(context,themeResId) {
    private val buyButton: ShapeTextView? by lazy { findViewById(R.id.tv_buy_vip) }

    private val layoutPayAli: ShapeRelativeLayout? by lazy { findViewById(R.id.layout_ali_pay)  }
    private val aliCheck: ImageView? by lazy { findViewById(R.id.iv_ali_checked)  }

    private val tvPrivacyProtocol : TextView? by lazy { findViewById(R.id.tv_privacy_protocol)  }
    private val btnClose : ImageView? by lazy { findViewById(R.id.btn_close)  }
    private val layoutPayWx: ShapeRelativeLayout? by lazy { findViewById(R.id.layout_wx_pay)  }
    private val wxCheck: ImageView? by lazy { findViewById(R.id.iv_wx_checked)  }


    private val privacyColor: Int by lazy {
        ContextCompat.getColor(context, R.color.color_5B3016)
    }

    //0微信 1支付宝
    private var payType = 0
    var listener:OnItemListener?=null

        init {
            setWidth(ViewUtils.getScreenWidth(context) - ViewUtils.dp2px(30f))
            setContentView(R.layout.dialog_buy_vip_dialog)
            setWindowAnimations(AnimAction.ANIM_IOS)
            setGravity(Gravity.CENTER)
            setCancelable(false)
            PrivacyProtocolHelper.setupPrivacyProtocolText(
                textView = tvPrivacyProtocol!!,
                privacyColor = privacyColor,
                protocolClickListener = {
                    WebViewActivity.launch(context, "会员服务协议", Constants.PrivacyUrl.protocol.url)
                },
                privacyClickListener = {
                    WebViewActivity.launch(context, "自动续费服务规则", Constants.PrivacyUrl.privacy.url)
                }
            )

            btnClose?.clickWithTrigger {
                listener?.onGiveUp()
            }

            buyButton?.clickWithTrigger {
                listener?.onBuyVip(payType)
            }


            layoutPayAli?.clickWithTrigger {
                payType = 1
                aliCheck?.visibility = View.VISIBLE
                wxCheck?.visibility = View.INVISIBLE
            }

            layoutPayWx?.clickWithTrigger {
                payType = 0
                aliCheck?.visibility = View.INVISIBLE
                wxCheck?.visibility = View.VISIBLE
            }

        }


    fun setPrice(salePrice:String,origin:String){

    }

    interface OnItemListener{
        fun onGiveUp()
        fun onBuyVip(payType:Int)
    }
}